package push2java;

/**
 *
 * @author James Pettit
 */
public class NumberInstructions {

    /*
    public static void INTEGER_ADD(State state) {
        if (state.integerStack.size() >= 2) {
            Integer arg1 = (Integer) state.integerStack.pop();
            Integer arg2 = (Integer) state.integerStack.pop();
            state.integerStack.push(arg1 + arg2);
        }
    }
     *
     */

    public static void FLOAT_ADD(State state) {
        if (state.floatStack.size() >= 2) {
            Float arg1 = (Float) state.floatStack.pop();
            Float arg2 = (Float) state.floatStack.pop();
            state.floatStack.push(arg1 + arg2);
        }
    }

    /*
    public static void INTEGER_SUB(State state) {
        if (state.integerStack.size() >= 2) {
            Integer arg1 = (Integer) state.integerStack.pop();
            Integer arg2 = (Integer) state.integerStack.pop();
            state.integerStack.push(arg1 - arg2);
        }
    }
     *
     */

    public static void FLOAT_SUB(State state) {
        if (state.floatStack.size() >= 2) {
            Float arg1 = (Float) state.floatStack.pop();
            Float arg2 = (Float) state.floatStack.pop();
            state.floatStack.push(arg1 - arg2);
        }
    }

    /*
    public static void INTEGER_MULT(State state) {
        if (state.integerStack.size() >= 2) {
            Integer arg1 = (Integer) state.integerStack.pop();
            Integer arg2 = (Integer) state.integerStack.pop();
            state.integerStack.push(arg1 * arg2);
        }
    }
     *
     */

    public static void FLOAT_MULT(State state) {
        if (state.floatStack.size() >= 2) {
            Float arg1 = (Float) state.floatStack.pop();
            Float arg2 = (Float) state.floatStack.pop();
            state.floatStack.push(arg1 * arg2);
        }
    }

    /*
    public static void INTEGER_DIV(State state) {
        if (state.integerStack.size() >= 2) {
            Integer arg1 = (Integer) state.integerStack.pop();
            Integer arg2 = (Integer) state.integerStack.pop();
            if (arg2 == 0) {
                state.integerStack.push(0);
            } else {
                state.integerStack.push(arg1 / arg2);
            }
        }
    }
     *
     */

    public static void FLOAT_DIV(State state) {
        if (state.floatStack.size() >= 2) {
            Float arg1 = (Float) state.floatStack.pop();
            Float arg2 = (Float) state.floatStack.pop();
            if (arg2 == 0) {
                state.floatStack.push(0f);
            } else {
                state.floatStack.push(arg1 / arg2);
            }
        }
    }

    public static void POW(State state) {
        if (state.floatStack.size() >= 2) {
            Float arg1 = (Float) state.floatStack.pop();
            Float arg2 = (Float) state.floatStack.pop();
            state.floatStack.push((float) Math.pow(arg1, arg2));
        }
    }

    public static void LOG(State state) {
        if (state.floatStack.size() >= 1) {
            Float arg1 = (Float) state.floatStack.pop();
            state.floatStack.push((float) Math.log(arg1));
        }
    }

    public static void SQRT(State state) {
        if (state.floatStack.size() >= 1) {
            Float arg1 = (Float) state.floatStack.pop();
            state.floatStack.push((float) Math.sqrt(arg1));
        }
    }
}
